'use strict';

/**
 * @ngdoc overview
 * @name sugarfreeMemberFrontendApp
 * @description
 * # sugarfreeMemberFrontendApp
 *
 * Main module of the application.
 */
angular
.module('sugarfreeMemberFrontendApp', [
		'ngAnimate',
		'ngCookies',
		'ngResource',
		'ngSanitize',
		'ngTouch',
		'ui.bootstrap',
		'ui.router',
		'lgOauth',
		'lgFilter'
])
.config(function ($stateProvider, $urlRouterProvider) {

	$urlRouterProvider.otherwise("/courses");

	$stateProvider
		/*
	.state('detail', {
		url: '',
		templateUrl: 'views/main.html',
		controller: 'MainCtrl',
		controllerAs: 'main'

	})
		 */
	.state('login', {
		url: '/login',
		templateUrl: 'views/login.html',
		controller: 'LoginCtrl',
		controllerAs: 'login'
	})
	.state('receipts', {
		url: '/receipts',
		templateUrl: 'views/receipts.html',
		controller: 'ReceiptsCtrl',
		controllerAs: 'receipts'
	})
	.state('oauth', {
		url: '/oauth/?code&state',
		templateUrl: 'views/loading.html',
		controller: 'OauthCtrl',
		controllerAs: 'oauth'
	})
	.state('receipt', {
		url: '/id/:id/title/:title/begin/:begin/price/:price/gym/:gym/type/:type',
		templateUrl: 'views/receipt.html',
		controller: 'ReceiptCtrl',
		controllerAs: 'receipt'
	})
	.state('order', {
		url: '/order',
		templateUrl: 'views/order.html',
		controller: 'OrderCtrl',
		controllerAs: 'order'
	})
	.state('courses', {
		url: '/courses',
		templateUrl: 'views/courses.html',
		controller: 'CourseListCtrl'
	})
	.state('lesson', {
		url: '/lesson/:id',
		templateUrl: 'views/lesson.html',
		controller: 'LessonDetailCtrl',
		resolve:{
			lessonId:function($stateParams){
				return $stateParams.id;
			}
		}
	})
	.state('course', {
		url: '/course/:id/gym/:gymId',
		templateUrl: 'views/course.html',
		controller: 'CourseDetailCtrl',
		resolve:{
			gymId:function($stateParams){
				return $stateParams.gymId;
			},
			programId:function($stateParams){
				return $stateParams.id;
			}
		}
	})
	.state('mine', {
		url: '/mine/:status',
		templateUrl: 'views/mine.html',
		controller: 'MineCtrl',
		resolve: {
			status:function($stateParams){
				var bitset = [false, false, false, false];
				var value = $stateParams.status || 0;
				angular.forEach(bitset, function(item, index){
					if(value & (1 << index)){
						bitset[index] = true;
					}
				});
				return bitset;
			}
		},
		controllerAs: 'mine'
	});
});
